// NOTE: refactored, iteration 1

using System;
using System.IO;
using System.Web.UI;
using System.Xml.XPath;
using System.Xml.Xsl;
using newtelligence.DasBlog.Web.Core.Config;

namespace newtelligence.DasBlog.Web
{
    public partial class BlogRollControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            XPathDocument xmlOpml = new XPathDocument(CoreFilePaths.BlogrollOpml);
            XslCompiledTransform xmlTransform = new XslCompiledTransform();
            xmlTransform.Load(CoreFilePaths.BlogrollXslt);

            // transform the opml
            using (StringWriter sw = new StringWriter())
            {
                xmlTransform.Transform(xmlOpml, null, sw);
                contentPlaceHolder.Controls.Add(new LiteralControl(sw.ToString()));
            }

            DataBind();
        }

        protected override void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            Load += Page_Load;
        }
    }
}